from app.BaseUsecase import BaseUsecase
import pandas as pd
import os
class XlsxUsecase(BaseUsecase):
    """
    xlsx用例加载实现
    """
    def load(self,config):
        print("加载xlsx用例")
        res = []
        dir = config['usecaseDir']
        for root,dirs,files in os.walk(dir):
            for file in files:
                if os.path.splitext(file)[1] in ['.xlsx']:
                    df = pd.read_excel(os.path.join(root,file))
                    # data = df.values
                    print("输出列标题",df.columns.values)
                    df.columns=['id','name','description','url','method','data','contentType','rule','expectedResult']
                    print("输出列标题-修改后",df.columns.values)
                    data = df.to_dict('records')
                    # 转换
                    for item in data:
                        if item['url'].startswith("http") == False:
                            item['url'] = item['url'].format(baseUrl=config['baseUrl'])
                    res.append({
                        "name": "name",
                        "description": "description",
                        "baseUrl": config['baseUrl'],
                        "items": data
                    })
        print(res)
        return res